    # calculations.py
import numpy as np
from math import log
class Calculation():

    def calculate_simpson_index(self,species_counts):
        total_count = sum(species_counts)
        if total_count == 0:
            return 0
        sum_proportions_squared = sum((count / total_count) ** 2 for count in species_counts)
        simpson_index = 1 - sum_proportions_squared
        return simpson_index

    def calculate_pielou_index(self,species_counts):
        total_count = sum(species_counts)
        if total_count == 0:
            return 0
        else:
            species_richness = len(species_counts)
            simpson_index = self.calculate_simpson_index(species_counts)
        if species_richness == 0:
            return 0
        else:
            pielou_index = simpson_index / log(species_richness)
        return pielou_index

    def calculate_sdo(self,temperature, salinity=0, pressure=1):
        return (14.6 - 0.4 * temperature + 0.008 * temperature**2) / (1.0 + 0.000014 * salinity * pressure)

    def calculate_tsi_tp(self,tp_concentration):
        return 14.42 * np.log(tp_concentration) + 4.15

    def calculate_dosp(self,actual_do, sdo):
        return (actual_do / sdo) * 100